﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class WebCommon_Job : System.Web.UI.Page
{
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    JobManager dllJobManager = new JobManager();
    public string _target = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        _target = Utility.HttpHelp.getParamsString("SID");        
        if (!IsPostBack)
        {
            bindListBox();
        }
    }

    /// <summary>
    /// 绑定ListBox
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-12</date>
    void bindListBox()
    {
        DataTable _select = new DataTable();
        _select = dllJobManager.get();
        for (int i = 0; i < _select.Rows.Count; i++)
        {
            ListItem _li = new ListItem(_select.Rows[i]["JobName"].ToString());
            lbxJobName.Items.Add(_li);
        }
    }

    /// <summary>
    /// 查询按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        this.lbxJobName.Items.Clear();
        if (txtSelect.Text.Length == 0)
        {
            bindListBox();
        }
        else
        {
            DataTable _select = new DataTable();
            object[] _value = new object[1];
            _value[0] = txtSelect.Text.Trim();
            _value[0] = "%" + _value[0] + "%";
            _select = dllJobManager.get(JobManager.field.JobName.ToString(), _value);
            if (_select.Rows.Count == 0)
            {
                Utility.HttpHelp.alert("没有发现你要查找的岗位", Page);
            }
            else
            {
                for (int i = 0; i < _select.Rows.Count; i++)
                {
                    ListItem _li = new ListItem(_select.Rows[i]["JobName"].ToString());
                    lbxJobName.Items.Add(_li);
                }
            }        
        }
    }
    /// <summary>
    /// 提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (this.lbxOk.Items.Count == 1)
        {
            ListItem _li = this.lbxOk.Items[0];
            Page.RegisterStartupScript("getPro", "<script language='javascript'>GetPro('" + _li.Text + "');</script>");
        }
        if (this.lbxOk.Items.Count == 0)
        {            
            Page.RegisterStartupScript("alert", "<script language='javascript'>alert('请选择一个岗位');</script>"); 
        }
        if (this.lbxOk.Items.Count>1)
        {
            Page.RegisterStartupScript("alert", "<script language='javascript'>alert('只能选择一个岗位');</script>");
        }
        

        
    }
    /// <summary>
    /// 添加岗位
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Session["SID"] = _target;
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('JobAdd.aspx','newwindow','height=160,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Utility.HttpHelp.closeWindowNoFresh("User_Manager.aspx", Page);
    }

    /// <summary>
    /// 选择事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSelect_Click1(object sender, EventArgs e)
    {
        ListItem _li = this.lbxJobName.SelectedItem;
        if (_li != null)
        {
            //排除重复选项
            ListItem _result = this.lbxOk.Items.FindByText(_li.Text);
            if (_result == null)
            {
                _result = new ListItem();
                _result.Text = _li.Text;
                _result.Value = _li.Value;
                this.lbxOk.Items.Add(_result);
            }
        }
        else
        {
            Utility.HttpHelp.alert("只能选择一个岗位", Page);
        }   
    }


    /// <summary>
    /// 移除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRemove_Click(object sender, EventArgs e)
    {
        ListItem _li = this.lbxOk.SelectedItem;
        if (_li != null)
        {
            this.lbxOk.Items.Remove(_li);
        }
    }


    //选择
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        ListItem _li = this.lbxJobName.SelectedItem;
        if (_li != null)
        {
            //排除重复选项
            ListItem _result = this.lbxOk.Items.FindByText(_li.Text);
            if (_result == null)
            {
                _result = new ListItem();
                _result.Text = _li.Text;
                _result.Value = _li.Value;
                this.lbxOk.Items.Add(_result);
            }
        }
        else
        {
            Utility.HttpHelp.alert("只能选择一个岗位", Page);
        } 
    }


    //移除
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        ListItem _li = this.lbxOk.SelectedItem;
        if (_li != null)
        {
            this.lbxOk.Items.Remove(_li);
        }
    }


    /// <summary>
    /// ListBox选择事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbxJobName_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListItem _li = this.lbxJobName.SelectedItem;
        if (_li != null)
        {
            //排除重复选项
            ListItem _result = this.lbxOk.Items.FindByText(_li.Text);
            if (_result == null)
            {
                _result = new ListItem();
                _result.Text = _li.Text;
                _result.Value = _li.Value;
                this.lbxOk.Items.Add(_result);
            }
        }
        else
        {
            Utility.HttpHelp.alert("只能选择一个岗位", Page);
        } 
    }
}
